<?
class act_mypct
{
   	/**
   	 * 功能:添加一个新的商品
   	 */
   	public function addGoodsInfo()
   	{
   	    global $scfg;
   	    $db_goods = &new db($scfg['db']['goods']);
		$rs = pct::addPctInfo($db_goods,$_POST,$_GET,$_FILES);
		if($rs[1]) echo g::msg($rs[1]);
		g::gowin($rs[2]);
   	}
   	/**
   	 * 功能:更新商品信息
   	 */
    public function modifyGoodsInfo()
    {
        global $scfg;
        $db_goods = &new db($scfg['db']['goods']);
		$rs = pct::modifyPctInfo($db_goods,$_POST,$_GET,$_FILES);
		if($rs[1]) echo g::msg($rs[1]);
		g::gowin($rs[2]);
    }
    /**
     * 功能:设定用户的IM
     */
    public function setUserIm()
    {
       global $scfg;
       $where = array(
			"str" =>" urs = ? ",
			"bind"=>urs
		);
		$bind = array(
			"urs"=>urs,
			"msn"=>$_POST["msn"],
			"yahoo"=>$_POST["yahoo"],
			"skype"=>$_POST["skype"],
			"qq"=>$_POST["qq"],
		);
		$db_member 	= new db($scfg['db']['member']);
		$db_member->replace("member_im",$bind);
		$db_member->update("member_log",array("im_check"=>1)," urs = ? ",urs);
		//echo $db_member->getsql();
		echo g::msg("成功:操作成功!");
		g::gowin(surl::get("my")."index.php?act=user_im");
    }
    /**
     * 功能:设定用户的基本信息
     */
    public function setUserInfo()
    {
        global $scfg;
        if($_POST["address_province_tw"])
		{
		    $_POST["address_province"] = "台湾";
		}else
		{
		    $_POST["address_province"] = $_POST["address_province_o"];
		    $_POST["address_city"] = $_POST["address_city_o"];
		    $_POST["address_borough"] = $_POST["address_borough_o"];
		}
		$bind = array(
			"urs"=>urs,
			"real_name"=>$_POST["real_name"],
			"email"=>$_POST["email"],
			"sex"=>$_POST["sex"],
			"birthday_yy"=>$_POST["birthday_yy"],
			"birthday_mm"=>$_POST["birthday_mm"],
			"birthday_dd"=>$_POST["birthday_dd"],
			"address_province"=>$_POST["address_province"],
			"address_province_tw"=>$_POST["address_province_tw"],
			"address_city"=>$_POST["address_city"],
			"address_borough"=>$_POST["address_borough"],
			"address"=>$_POST["address"],
			"zip"=>$_POST["zip"],
			"mobile"=>$_POST["mobile"],
			"country"=>$_POST["country"],
			"zone_country"=>$_POST["zone_country"],
			"zone_letter"=>$_POST["zone_letter"],
			"tel"=>$_POST["tel"],
			"tel_ext"=>$_POST["tel_ext"],
			"tel2"=>$_POST["tel2"],
			"mostly_tel"=>$_POST["mostly_tel"]
		);
		$db_member 	= new db($scfg['db']['member']);
		$db_member->replace("member_base",$bind);
		$db_member->update("member_log",array("base_check"=>1)," urs = ? ",urs);
		if($bind["email"])
		{
		    $db_member->update("member_main",array("mail"=>$bind["email"])," urs = ? ",urs);
		}
		//echo $db_member->getsql();
		g::gowin(surl::get("my")."index.php?act=user_info");
    }
    /**
     * 功能:更改用户密码
     */
    public function setUserPwd()
    {
        global $scfg;
        $db_member 	= new db($scfg['db']['member']);
		$rs = u::modifyPass(urs,$_POST["pwd"],$_POST["new_pwd"]);
		echo g::msg($rs[1]);
		if($rs[0])
		{
		    g::gowin(surl::get("my")."index.php");
		}else
		{
		    g::gowin();
		}
    }
    /**
     * 功能:设定用户的密码保护
     */
    public function setUserSafe()
    {
        global $scfg;
        $db_member 	= new db($scfg['db']['member']);
		$where = array(
			"str" => " where urs = ? ",
			"bind"=>urs
		);
		$rs = $db_member->row("select * from member_safe {$where['str']} limit 1",$where['bind']);
		$init = ($rs && $rs["ssn"]&& $rs["safe_email"]&& $rs["safe_pwd"]&& $rs["question1"]&& $rs["answer1"]&& $rs["question2"]&& $rs["answer2"])?0:1;
		if($_POST["init"] == $init && $init==1)
		{
		    $bind = array(
				"urs"=>urs,
				"ssn"=>$_POST["ssn"],
				"safe_email"=>$_POST["safe_email"],
				"safe_pwd"=>md5($_POST["safe_pwd"]),
				"question1"=>$_POST["question1"],
				"answer1"=>$_POST["answer1"],
				"question2"=>$_POST["question2"],
				"answer2"=>$_POST["answer2"]
			);
			$db_member->replace("member_safe",$bind);
			$db_member->update("member_log",array("safe_check"=>1)," urs = ? ",urs);
			echo g::msg("成功:设定密码保护成功!");
			g::gowin(surl::get("my")."index.php");
		}elseif($_POST["init"] == $init && $init==0)
		{
		    if($rs["ssn"]." " == $_POST["ssn"]." "
		    	&&$rs["safe_email"] == $_POST["safe_email"]
		    	&&$rs["safe_pwd"] == md5($_POST["safe_pwd"])
		    	&&$rs["question1"] == $_POST["question1"]
		    	&&$rs["answer1"] == $_POST["answer1"]
		    	&&$rs["question2"] == $_POST["question2"]
		    	&&$rs["answer2"] == $_POST["answer2"])
		    {
		        $bind = array(
					"safe_email"=>$_POST["safe_email_new"],
					"safe_pwd"=>md5($_POST["safe_pwd_new"]),
					"question1"=>$_POST["question1_new"],
					"answer1"=>$_POST["answer1_new"],
					"question2"=>$_POST["question2_new"],
					"answer2"=>$_POST["answer2_new"]
				);
				$db_member->update("member_safe",$bind," urs = ? ",$where["bind"]);
				$db_member->update("member_log",array("safe_check"=>1)," urs = ? ",urs);
				//echo $db_member->getsql()."<br />";
				echo g::msg("成功:设定密码保护成功!");
				g::gowin(surl::get("my")."index.php");
		    }elseif($rs["ssn"]." " != $_POST["ssn"]." ")
		    {
		     	echo g::msg("提示:身份证字号有误!");
		    }elseif($rs["safe_email"]!= $_POST["safe_email"])
		    {
		     	echo g::msg("提示:安全邮箱有误!");
		    }elseif($rs["safe_pwd"] != md5($_POST["safe_pwd"]))
		    {
		     	echo g::msg("提示:安全密码有误!");
		    }elseif($rs["question1"] != $_POST["question1"]
		    	|| $rs["answer1"] != $_POST["answer1"])
		    {
		     	echo g::msg("提示:第一个提问回答有误!");
		    }elseif($rs["question2"] != $_POST["question2"]
		    	||$rs["answer2"] != $_POST["answer2"])
		    {
		     	echo g::msg("提示:第二个提问回答有误!");
		    }else
		    {
		        echo g::msg("提示:操作失败!");
		    }
		    g::gowin();
		}else
		{
			echo g::msg("提示:操作失败!");
			g::gowin();
		}
    }
    /**
     * 功能:收货地址设定
     */
    public function addUserAddr()
    {
        global $scfg;
        $db_member 	= new db($scfg['db']['member']);
		$where = array(
			"str" => " where urs = ? ",
			"bind"=>urs
		);
		$rs = $db_member->rows("select id from member_addr {$where['str']}",$where['bind']);
		if($rs<=20)
		{
			$bind = array(
				"urs"=>urs,
				"real_name"=>$_POST["real_name"],
				"country"=>$_POST["country"],
				"address_province"=>$_POST["address_province"],
				"address_city"=>$_POST["address_city"],
				"address_borough"=>$_POST["address_borough"],
				"address"=>$_POST["address"],
				"zip"=>$_POST["zip"],
				"tel"=>$_POST["tel"]
			);
			$rs = $db_member->insert("member_addr",$bind);
			if($rs)
			{
			    echo g::msg("成功:地址添加成功!");
				g::gowin(surl::get("my")."index.php?act=user_add");
			}else
			{
			    echo g::msg("提示:系统忙,请稍后再试!");
			    g::gowin();
			}
		}else
		{
		     echo g::msg("提示:你添加的地址太多,请删除后再添加!");
		     g::gowin();
		}
    }
    /**
     * 功能:用户删除他设定的地址
     */
    public function delUserAddr()
    {
        global $scfg;
        $db_member 	= new db($scfg['db']['member']);
		$where = array(
			"str" => " id= :id and urs = :urs ",
			"bind"=>array("urs"=>urs,"id"=>$_GET["id"])
		);
		$db_member->delete("member_addr",$where["str"],$where["bind"]);
		echo g::msg("成功:删除地址成功!");
		g::gowin(surl::get("my")."index.php?act=user_add");
    }
    /**
     * 功能:用户开店
     */
    public function sellOpenShop()
    {
        global $scfg;
        $db_member 	= new db($scfg['db']['member']);
	    $my_log  	=  $db_member->row("select * from member_log where urs = ? ",urs);
		if(//!$my_log['email_check'] || 
			!$my_log['safe_check']
			|| !$my_log['im_check']
			|| !$my_log['base_check'])
		{
			echo g::msg("提示:您还没有\"账户设定提醒\"中的必要设置!");
			g::gowin(surl::get("my")."index.php");
		}else
		{
			$rs=$db_member->update("member_log",array("shop_check"=>1)," urs = ? ",urs);
			if($rs)
			{
			    echo g::msg("成功:小店開通成功");
			    g::gowin(surl::get("my")."index.php?act=sell_manage_basicset");
			}else
			{
			    echo g::msg("提示:系统忙,请稍后再试!");
				g::gowin();
			}
		}
    }
    /**
     * 功能:基本设置 - 小店管理
     */
    public function setManageBasicset()
    {
        global $scfg;
        $db_goods = &new db($scfg['db']['goods']);
		$rs = shop::setInfo($db_goods,urs,$_POST,$_FILES);
		//echo g::msg($rs[1]);
		g::gowin(surl::get("my")."index.php?act=sell_manage_basicset");
    }
    /**
     * 功能:公告设置 - 小店管理
     */
    public function setManageBasicset_summary()
    {
        global $scfg;
        $db_goods = &new db($scfg['db']['goods']);
		$rs = shop::setInfo($db_goods,urs,$_POST);
		//echo g::msg($rs[1]);
		g::gowin(surl::get("my")."index.php?act=sell_manage_updateBBSEntry");
    }
    /**
     * 功能:自定义分类
     */
    public function setManageSort()
    {
        global $scfg;
        $db_goods 	= new db($scfg['db']['goods']);
		$where = array(
			"str" => " where urs = ? ",
			"bind"=>urs
		);
		$rs = $db_goods->rows("select cid from shop_class_id {$where['str']}",$where['bind']);
		if($rs<=20)
		{
			$shop_info  = $db_goods->row("select sid from shop_info where urs = ? limit 1",urs);
			$bind = array(
				"sid"=>$shop_info["sid"],
				"urs"=>urs,
				"className"=>$_POST["className"],
				"taxis"=>$_POST["taxis"],
			);
			$rs = $db_goods->insert("shop_class_id",$bind);
			//echo $db_goods->getsql();
			//exit();
			if($rs)
			{
			    //echo g::msg("成功:添加成功");
				g::gowin(surl::get("my")."index.php?act=sell_manage_sort");
			}else
			{
			    echo g::msg("提示:系统忙,请稍后再试!");
				g::gowin();
			}
		}else
		{
		    echo g::msg("提示:你添加的分类太多,请删除后再添加!");
		    g::gowin();
		}
    }
    public function delManageSort()
    {
        global $scfg;
        $db_goods 	= new db($scfg['db']['goods']);
		$where = array(
			"str" => " cid= :cid and urs = :urs ",
			"bind"=>array("urs"=>urs,"cid"=>$_GET["cid"])
		);
		$db_goods->delete("shop_class_id",$where["str"],$where["bind"]);
		//echo g::msg("成功:删除分类成功!");
		g::gowin(surl::get("my")."index.php?act=sell_manage_sort");
    }
    public function modifyManageSort()
    {
        global $scfg;
        $db_goods 	= new db($scfg['db']['goods']);
		$where = array(
			"str" => " cid= :cid and urs = :urs ",
			"bind"=>array("urs"=>urs,"cid"=>$_POST["cid"])
		);
		$bind = array(
			"className"=>$_POST["className"],
			"taxis"=>$_POST["taxis"],
		);
		$db_goods->update("shop_class_id",$bind,$where["str"],$where["bind"]);
		//echo g::msg("成功:更新分类成功!");
		g::gowin(surl::get("my")."index.php?act=sell_manage_sort");
    }
    /**
     * 功能:友情链接
     */
    public function setUserIm()
    {
        global $scfg;
        $db_goods 	= new db($scfg['db']['goods']);
		$where = array(
			"str" => " where urs = ? ",
			"bind"=>urs
		);
		$rs = $db_goods->rows("select cid from shop_friendlink  {$where['str']}",$where['bind']);
		if($rs<=20)
		{
			$shop_info  = $db_goods->row("select sid from shop_info where urs = ? limit 1",urs);
			$bind = array(
				"sid"=>$shop_info["sid"],
				"urs"=>urs,
				"siteName"=>$_POST["siteName"],
				"url"=>$_POST["url"],
				"taxis"=>$_POST["taxis"],
			);
			$rs = $db_goods->insert("shop_friendlink",$bind);
			//echo $db_goods->getsql();
			//exit();
			if($rs)
			{
			    //echo g::msg("成功:添加成功");
				g::gowin(surl::get("my")."index.php?act=sell_manage_friendlink");
			}else
			{
			    echo g::msg("提示:系统忙,请稍后再试!");
				g::gowin();
			}
		}else
		{
		    echo g::msg("提示:你添加的分类太多,请删除后再添加!");
		    g::gowin();
		}
    }
    public function delManageFriendlink()
    {
        global $scfg;
        $db_goods 	= new db($scfg['db']['goods']);
		$where = array(
			"str" => " id= :id and urs = :urs ",
			"bind"=>array("urs"=>urs,"id"=>$_GET["id"])
		);
		$db_goods->delete("shop_friendlink",$where["str"],$where["bind"]);
		//echo g::msg("成功:删除分类成功!");
		g::gowin(surl::get("my")."index.php?act=sell_manage_friendlink");
    }
    public function modifyManageFriendlink()
    {
        global $scfg;
        $db_goods 	= new db($scfg['db']['goods']);
		$where = array(
			"str" => " id= :id and urs = :urs ",
			"bind"=>array("urs"=>urs,"id"=>$_POST["id"])
		);
		$bind = array(
			"siteName"=>$_POST["siteName"],
			"url"=>$_POST["url"],
			"taxis"=>$_POST["taxis"],
		);
		$db_goods->update("shop_friendlink",$bind,$where["str"],$where["bind"]);
		//echo g::msg("成功:更新分类成功!");
		g::gowin(surl::get("my")."index.php?act=sell_manage_friendlink");
    }
    /**
     * 功能:删降商品
     */
    public function Pctdel()
    {
        global $scfg;
    }
    /**
     * 功能:删降用户名
     */
    public function PctUploadDate()
    {
        global $scfg;
    }
    /**
     * 功能:删降用户名
     */
    public function PctDown()
    {
        global $scfg;
    }
    /**
     * 功能:删降用户名
     */
    public function PctGood()
    {
        global $scfg;
    }
}
?>